
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>门信息管理</title>

<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="/js/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/func.js"></script>

<script type="text/javascript">
		
	function deleteGate()
	{
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0)
		{
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];
		for(var i=0;i<selectedRows.length;i++)
		{
			strIds.push(selectedRows[i].skid);
		}
		
		var ids=strIds.join(",");
		
	    $.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r)
			{
				if(r)
				{
					$.post("/class/gateDelete.php",{delIds:ids},function(result)
					{
						if(result.success)
						{
							$.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNums+"</font>条数据！");
							$("#dg").datagrid("reload");
						}else
						{
							$.messager.alert('系统提示',result.errorMsg);
						}
					},"json");
				}
			});
	}
	
	function openGateAddDialog()
	{
		$("#dlg").dialog("open").dialog("setTitle","添加控制信息");
		$("#skidtr").hide();
		url="/class/gateSave.php";
	}
		
	function openGateModifyDialog()
	{
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1)
		{
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#skidtr").hide();
		$("#dlg").dialog("open").dialog("setTitle","编辑控制信息");
		$("#fm").form("load", row);

		url="/class/gateSave.php";		
	}
	
	function closeGateDialog()
	{
		$("#dlg").dialog("close");
		resetValue();
	}
	
	function resetValue()
	{
		$("#gatenumber").val("");
		$("#deviceid").val("");
		$("#ipaddr").val("");
	}

	function jianchageshi()
	{
		if(!valid_port0($('#serverPORT').val()))
	    {
	        $.messager.alert("系统提示",'请正确输入WEB服务器PORT。\n温馨提示：只能输入1-65534之间的整数。');
	        return false;
	    }
	    if(!valid_port0($('#tcpPORT').val()))
	    {
	    	$.messager.alert("系统提示",'请正确输入TCP服务器PORT。\n温馨提示：只能输入1-65534之间的整数。');
	        return false;
	    }
	    if(!checkIp12(document.getElementById("CameraADDR")))
    	{
	    	$.messager.alert("系统提示",'请正确输入摄像头IP。');
	        return false;
	    }
	    if(!valid_port0($('#CameraPORT').val()))
	    {
	    	$.messager.alert("系统提示",'请正确输入摄像头PORT。\n温馨提示：只能输入1-65534之间的整数。');
	        return false;
	    }
/*	    if($('#CameraRTSP').val().match(/^[0-9A-Za-z/@:_.*-//]{1,256}$/))
    	{
    		$.messager.alert("系统提示",'请正确输入摄像头RTSP,只能输入数字、字母和/@:_.*-字符。');
	        return false;
    	}
    	if($('#realtimepath').val().match(/^[0-9A-Za-z/@:_.*-//]{1,256}$/))
    	{
    		$.messager.alert("系统提示",'请正确输入实时上传路径,只能输入数字、字母和/@:_.*-字符。');
	        return false;
    	}*/
    	if(!checkIp12(document.getElementById("serverIP")))
    	{
	    	$.messager.alert("系统提示",'请正确输入服务器IP。');
	        return false;
	    }
	    if(!checkIp12(document.getElementById("IP")))
    	{
	    	$.messager.alert("系统提示",'请正确输入控制器IP。');
	        return false;
	    }
	    if(!valid_port0($('#PORT').val()))
	    {
	    	$.messager.alert("系统提示",'请正确输入控制器PORT。\n温馨提示：只能输入1-65534之间的整数。');
	        return false;
	    }
	}

	function saveGate()
	{
		if(jianchageshi()===false)
		{
			return;
		}
		$("#fm").form("submit",
		{
			url:url,
			onSubmit:function()
			{
//				$("#skidtr").val("");
				return $(this).form("validate");
			},
			success:function(result)
			{
				if(result.errorMsg)
				{
					$.messager.alert("系统提示",result.errorMsg);
					return;
				}else
				{
//					$.messager.alert("系统提示","保存成功");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}
			}
		});
	}

	function dwqidong(val, row)
	{
//		return '<a href="/dwbrowser.php?action=dwdongtaiqidong"> <\a>';
		var dwjson='{"action":"dwrlqidong"}';
		$.post("../dwbrowser.php",{dwjson},function(result)
		{
			if(result.success)
			{
				$.messager.alert("系统提示","您已成功启动人脸识别.");
				$("#dg").datagrid("reload");
			}else
			{
				$.messager.alert('系统提示',result.errorMsg);
			}
		},"json");
	}

	function dwtingzhi(val, row)
	{
		var dwjson='{"action":"dwrltingzhi"}';
		$.post("../dwbrowser.php",{dwjson},function(result)
		{
			if(result.success)
			{
				$.messager.alert("系统提示","您已成功停止人脸识别.");
				$("#dg").datagrid("reload");
			}else
			{
				$.messager.alert('系统提示',result.errorMsg);
			}
		},"json");
	}
	function ajaxGetControlerNum()
	{
	    $.ajax
		({
	        url: "/dwbrowser.php",
	        type: "POST",
	        timeout: 180000,
	        data: "{\"action\":\"dwgetcontrolernum\"}",
	        dataType: "text",
	//			async: true,
	        error: function()
			{
			    $('#massage_text').text('网络错误。'); 
	            return false;
	        },
	        complete: function()
			{              
	            if (status === 'timeout')
				{
	                $('#massage_text').text('超时。');
					this.abort();
	            }
	        },
	        success: function(deReturn)
			{
	            var DcSelection_element = document.getElementById("controlerNum");
	            var dcSelectiontab =jQuery.parseJSON(deReturn); 
	//            alert("nrows:"+dcSelectiontab.nrows+" 1:"+dcSelectiontab['s1_0']+" 7:"+dcSelectiontab['s7_0']);			
				for(var i=1;i<=dcSelectiontab.nrows;i++)
	            {
					DcSelection_element.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
				}			
		    }
	    });	
	}
	$(document).ready(function()
	{
		ajaxGetControlerNum();
	});	
</script>
</head>
<body>
	<table id="dg" title="门信息表" class="easyui-datagrid" fitColumns="true"
	 pagination="true" rownumbers="true" url="/class/gateList.php" fit="true" toolbar="#toolbar">
		<thead>
			<tr>
			    <th field="checkbox" checkbox="true"></th>
				<th field="skid" width="25" align="center" hidden="true">序号</th>
				<th field="controlernum" width="70"align="center">控制器</th>
				<th field="gatenum" width="25" align="center">闸号</th>				
				<th field="lianjie" width="50" align="center">连接状态</th>
				<th field="lasttime" width="120" align="center">最近连接时间</th>
				<th field="serverIP" width="60" align="center">服务器 IP</th>
				<th field="serverPORT" width="90" align="center">WEB服务器PORT</th>
				<th field="tcpPORT" width="90" align="center">TCP服务器PORT</th>
				<th field="realtimepath" width="80" align="center">实时上传路径</th>
				<th field="jianquanfangshi" width="60" align="center">鉴权方式</th>
				<th field="CameraRTSP" width="100" align="center">摄像头 RTSP</th>
				<th field="CameraADDR" width="100" align="center">摄像头 IP</th>
				<th field="CameraPORT" width="100" align="center">摄像头 PORT</th>
				<th field="IP" width="60" align="center">控制器 IP</th>
				<th field="PORT" width="80" align="center">控制器 PORT</th>				
			</tr>
		</thead>
	</table>
	
	<div id="toolbar">
		<div>
			<a href="javascript:openGateAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:openGateModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteGate()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:dwqidong()" class="easyui-linkbutton" iconCls="icon-tip" plain="true">人脸识别启动  </a>
			&nbsp;&nbsp;<a href="javascript:dwtingzhi()" class="easyui-linkbutton" iconCls="icon-cancel" plain="true">人脸识别停止  </a>
		</div>
	</div>	


	<div id="dlg" class="easyui-dialog" style="width: 450px;height: 380px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table>
				<tr id="skidtr">
					<td>序号：</td>
					<td><input type="text" name="skid" id="skid" class="easyui-validatebox"/></td>
				</tr>
				<tr>
					<td>控制器：</td>
					<td><input type="text" name="controlernum" id="controlernum" class="easyui-validatebox" required="true"/></td>
					<!--<td>
						<select name="controlerNum" id="controlerNum" class="easyui-validatebox" required="true">                               
                                  <!--<added by initValue>	 
                        </select>
                    </td>-->
				</tr>
				<tr>
					<td>闸号：</td>
					<!--<td><input type="text" name="gatenum" id="gatenum" value="0" class="easyui-validatebox" required="true"/></td>-->
					<td>
					    <select id="gatenum" name="gatenum" class="easyui-validatebox" required="true">
                            <option value="all" selected="selected">全部闸</option>
                            <option value="0">一号闸</option>
                            <option value="1">二号闸</option>
                            <option value="2">三号闸</option>
                            <option value="3">四号闸</option>
                        </select>
                    </td>
				</tr>				
				<tr>
					<td>服务器 IP：</td>
					<td><input type="text" name="serverIP" id="serverIP" value="127.0.0.1" class="easyui-validatebox" required="false"/></td>
				</tr>
				<tr>
					<td>WEB服务器PORT：</td>
					<td><input type="text" name="serverPORT" id="serverPORT" value="1118" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>TCP服务器PORT：</td>
					<td><input type="text" name="tcpPORT" id="tcpPORT" value="1119" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>实时上传路径：</td>
					<td><input type="text" name="realtimepath" id="realtimepath" value="/dwrealtime.php" class="easyui-validatebox" required="true"/></td>
				</tr>				
				<tr>
					<td>鉴权方式：</td>
					<!--<td><input type="text" name="jianquanfangshi" id="jianquanfangshi" value="集中鉴权" class="easyui-validatebox" required="false"/></td>-->
					<td>
						<select name="jianquanfangshi" id="jianquanfangshi" class="easyui-validatebox" required="false">
	                       <option value="jizhong">集中鉴权</option>
	                       <option value="bendi">本地鉴权</option>                      
	                    </select>
	                </td>
				</tr>
				<tr>
					<td>摄像头 RTSP：</td>
					<td><input type="text" name="CameraRTSP" id="CameraRTSP" value="127.0.0.1" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>摄像头 IP：</td>
					<td><input type="text" name="CameraADDR" id="CameraADDR" value="127.0.0.1" class="easyui-validatebox" required="true"/></td>
				</tr>				
				<tr>
					<td>摄像头 PORT：</td>
					<td><input type="text" name="CameraPORT" id="CameraPORT" value="80" class="easyui-validatebox" required="false"/></td>
				</tr>
				<tr>
					<td>控制器 IP：</td>
					<td><input type="text" name="IP" id="IP" value="10.10.10.254" class="easyui-validatebox" required="true"/></td>
				</tr>				
				<tr>
					<td>控制器 PORT：</td>
					<td><input type="text" name="PORT" id="PORT" value="1118" class="easyui-validatebox" required="false"/></td>
				</tr>	
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveGate()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeGateDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>

</body>

</html>
